package threadpool;


import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class CreateThreadWays {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        new MyThread1().start();

        new Thread(new MyThread2()).start();

        FutureTask<Integer> futureTask = new FutureTask<>(new MyThread3());
        new Thread(futureTask).start();
        futureTask.get();

        /*
            1.继承Thread类
            2.实现Callable接口
            3.实现Runnable接口
         */
    }
}


//1.继承Thread类
class MyThread1 extends Thread{
    @Override
    public void run() {
        System.out.println("继承Thread类");
    }
}

//2.实现Runnable接口
class MyThread2 implements Runnable{
    @Override
    public void run() {
        System.out.println("实现Runnable接口");
    }
}

//3.实现Callable接口
class MyThread3 implements Callable<Integer> {
    @Override
    public Integer call() throws Exception {
        System.out.println("实现Callable接口");
        return 1;
    }
}
